public class Text1 {
    //209.长度最小的子数组
    public int minSubArrayLen(int target, int[] nums) {
        int sum = 0,ret = Integer.MAX_VALUE;
        int n = nums.length;

        for (int left = 0,right = 0; right < n ; right++){
            sum += nums[right];
            while(sum >= target){

                ret =  Math.min(ret,right - left + 1);
                sum -= nums[left++];
            }
        }

        return ret ==Integer.MAX_VALUE ? 0 : ret;
    }
}
